package artid.com.arttogoa.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class HView extends View {
	private Bitmap bmp;
	private Paint paint;
	private Context context;
	/** ���� */
	private Paint mPaint;
	private boolean HU = false;

	public HView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub

	}

	public HView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		this.context = context;
		this.paint = new Paint();
		this.paint.setAntiAlias(true); // �����
		this.paint.setStyle(Paint.Style.STROKE); // ���ƿ���Բ
		// TODO Auto-generated constructor stub
	}

	public HView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	private int circleX;
	private int circleY;

	public void setPainting(int circleX, int circleY) {
		this.HU = true;
		this.circleX = circleX;
		this.circleY = circleY;
		invalidate();
	}

	public void rePainting() {
		this.HU = false;
		invalidate();
	}

	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		// System.out.println("micw = " + this.getWidth() + ",mich="
		// + this.getHeight());
		if (HU) {
			// System.out.println("bmp��Ϊ��");
			// this.setVisibility(View.VISIBLE);
			// Matrix matrix = new Matrix();
			// canvas.drawBitmap(bmp, matrix, mPaint);

			// int center = getWidth() / 2;
			int innerCircle = dip2px(context, 5); // ������Բ�뾶
			int ringWidth = dip2px(context, 1); // ����Բ�����

			// ������Բ
			this.paint.setARGB(155, 230, 0, 0);
			this.paint.setStrokeWidth(2);
			canvas.drawCircle(circleX, circleY, innerCircle, this.paint);
			// ����Բ��
			this.paint.setARGB(155, 230, 0, 0);
			this.paint.setStrokeWidth(ringWidth);
			canvas.drawCircle(circleX, circleY,
					innerCircle + 1 + ringWidth / 2, this.paint);
			// ������Բ
			this.paint.setARGB(155, 230, 0, 0);
			this.paint.setStrokeWidth(2);
			canvas.drawCircle(circleX, circleY, innerCircle + ringWidth,
					this.paint);

		} else {
			// System.out.println("bmpΪ��");
			// this.setVisibility(View.GONE);
		}
	}

	/**
	 * ����ֻ�ķֱ��ʴ� dp �ĵ�λ ת��Ϊ px(����)
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
}
